JGENAM=jg
JGE_BRANCH=${JGE_BRANCH:-master}
JGE_URL="https://gitlab.com/jgemu/$JGENAM.git"

JGFNAM=jgrf
JGF_BRANCH=${JGF_BRANCH:-master}
JGF_URL="https://gitlab.com/jgemu/$JGFNAM.git"

PKG="$HOME"/games/emu/jgemu
JGE=${JGE:-"$GITSRC"}/jgemu/$JGENAM
JGE_TMP="$TMP"/../$JGENAM
JGF=${JGF:-"$GITSRC"}/jgemu/$JGFNAM
JGF_TMP="$TMP"/../$JGFNAM
SRC="$GITSRC"/jgemu/$PRGNAM
TMP="$TMP"/jgemu/$PRGNAM

_jgmake () {
  _makefile="$1"
  shift
  _make all "$SRC/$_makefile" \
    "${@:-}" \
    DISABLE_MODULE=1 \
    ENABLE_STATIC_JG=1 \
    CFLAGS_JG="-I$JGE/.."
  unset _makefile
  TMP="$TMP"/../$JGFNAM \
  _make "$_jginstall" "$JGF/Makefile" \
    BUILD_STATIC="$TMP"/$PRGNAM \
    CFLAGS="$BLDFLAGS" \
    CFLAGS_JG="-I$JGE/.." \
    PREFIX="$PKG" \
    BINDIR="$PKG"/games \
    DATADIR="$PKG"/share/games \
    DESTDIR="$DST"
}

if [ "${DEBUG:=0}" != 0 ]; then
  _jginstall='install'
else
  _jginstall='install-strip'
fi

if [ "$PRGNAM" != "$JGENAM" ]; then
  _git "$JGE" "$JGENAM" "$JGE_URL" "$JGE_TMP" "$JGE_BRANCH" "${JGE_COMMIT:-}" ''
  _git "$JGF" "$JGFNAM" "$JGF_URL" "$JGF_TMP" "$JGF_BRANCH" "${JGF_COMMIT:-}" ''
  _flags
fi

_git "$SRC" "$PRGNAM" "$URL" "$TMP" "$BRANCH" "${COMMIT:-}" ''
